// pages/integralMall/index/index.js
const app = getApp()
import api from '../../../utils/api.js'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		indicatorDots: true,
		vertical: false,
		autoplay: true,
		interval: 2000,
		duration: 500,
		isHide: true,
		shopData: null,
		shopDataNum: null,
		shopUrl: app.globalData.host,
		shopId: 1,
		shopListData: [],
	},
	goIntegral() {
		wx.navigateTo({
			url: '/pages/personal/curIntegral/curIntegral'
		})
	},
	goShopDetail(e) {
		let shopid = e.currentTarget.dataset.index;
		wx.navigateTo({
			url: '/pages/integralMall/mallDetail/mallDetail?id=' + shopid
		})
	},
	tabData(e) {
		var that = this;
		let apis = api.api;
		let listUrl = apis.host + 'goods/listGoods';
		that.setData({
			shopId: e.currentTarget.dataset.index
		})
		let listData = {
			cid: e.currentTarget.dataset.index,
			/* 否	string	分类ID */
			page: 1,
			/* 否	string	当前页数 */
			pagesize: 10,
			/* 否	string	每页配额 */
		}
		apis.request(listUrl, listData, 'POST').then(function(res) {
			that.setData({
				shopListData: res.data.list
			})
		}).catch(function(res) {
		})
	},
	getData() {
		var that = this
		// https://dageda.api.hjdz.ltd/goods/listCate
		let apis = api.api;
		let url = apis.host + 'goods/listCate';
		let listUrl = apis.host + 'goods/listGoods';
		let listData = {
			cid: 1,
			/* 否	string	分类ID */
			page: 1,
			/* 否	string	当前页数 */
			pagesize: 10,
			/* 否	string	每页配额 */
		}
		let data = {};
		apis.request(url, data, 'POST').then(function(res) {
			if (res.data.length <= 4) {
				if (res.data.length <= 2) {
					that.setData({
						indicatorDots: false,
						isHide: true,
						shopData: res.data,
						shopDataNum: 2
					})
				} else {
					that.setData({
						indicatorDots: false,
						isHide: true,
						shopData: res.data,
						shopDataNum: res.data.length
					})
				}
			} else {
				that.setData({
					indicatorDots: true,
					isHide: false,
					shopData: res.data
				})
			}
		}).catch(function(res) {
		})
		apis.request(listUrl, listData, 'POST').then(function(res) {
			that.setData({
				shopListData: res.data.list
			})
		}).catch(function(res) {
		})
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		var that = this
		that.getData()
	},
})
